package com.example.icongyou.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import com.example.icongyou.R;
import com.example.icongyou.adapter.DashboardPagerAdapter;
import com.google.android.material.tabs.TabLayout;

public class DashboardActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);

        initViews();
        setupViewPager();
        setupBackButton();

        // 从Intent获取默认标签并设置选中
        Intent intent = getIntent();
        int defaultTab = intent.getIntExtra("default_tab", 0); // 默认选中个人看板
        viewPager.setCurrentItem(defaultTab);
    }

    private void initViews() {
        tabLayout = findViewById(R.id.tab_layout);
        viewPager = findViewById(R.id.view_pager);
    }

    private void setupViewPager() {
        DashboardPagerAdapter adapter = new DashboardPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    /**
     * 设置返回按钮点击事件，返回上一页面
     */
    private void setupBackButton() {
        ImageView ivBack = findViewById(R.id.iv_back);
        ivBack.setOnClickListener(v -> {
            finish(); // 关闭当前页面
            // 添加上可选：添加页面切换动画，与项目其他页面保持一致
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        });
    }
}